package com.chen.filter;

import java.io.IOException;

import javax.servlet.Filter;
import javax.servlet.FilterChain;
import javax.servlet.FilterConfig;
import javax.servlet.ServletException;
import javax.servlet.ServletRequest;
import javax.servlet.ServletResponse;
import javax.servlet.http.HttpServletRequest;

/**
 * <b>计算页面操作、请求所花时间拦截器</b>
 * <p>
 * 描述:<br>
 * 拦截器的实现需要实现Filter接口
 * @author 威 
 * <br>2018年5月22日 下午8:13:25 
 * @see
 * @since 1.0
 */

public class TimeFilter implements Filter{
	@Override
	public void destroy() {
		System.out.println(this.getClass().getSimpleName()+"销毁");
	}
	@Override
	public void doFilter(ServletRequest request, ServletResponse response,
			FilterChain chain)
			throws IOException, ServletException {
		System.out.println(this.getClass().getSimpleName()+"进行拦截");
		long startTime = System.currentTimeMillis();
		chain.doFilter(request, response);
		long endTime = System.currentTimeMillis();
		System.out.println(((HttpServletRequest) request).getServletPath()+"页面请求所花时间"+(endTime-startTime));
	}
	@Override
	public void init(FilterConfig arg0) throws ServletException {
		System.out.println(this.getClass().getSimpleName()+"初始化");
	}

}
